<template>
  <div class="login-container">
    <!-- 顶部logo区域 -->
    <div class="header">
      <i class="el-icon-arrow-left back-icon" @click="goToHome"></i>
      <div class="logo-container" @click="goToHome">
        <span class="platform-title">实验室预约平台</span>
      </div>
    </div>

    <!-- 登录表单区域 -->
    <div class="login-form">
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules">
        <h2 class="login-title">用户登录</h2>
        <el-form-item prop="uName">
          <el-input
            v-model="loginForm.uName"
            placeholder="请输入用户名"
            prefix-icon="el-icon-user"
          />
        </el-form-item>

        <el-form-item prop="password" class="password-input">
          <el-input
            v-model="loginForm.password"
            :type="passwordVisible ? 'text' : 'password'"
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
          >
            <i
              slot="suffix"
              :class="[
                'password-eye',
                passwordVisible ? 'el-icon-view' : 'el-icon-hide',
              ]"
              @click="passwordVisible = !passwordVisible"
            ></i>
          </el-input>
        </el-form-item>

        <div class="forgot-password">
          <el-link type="primary" @click="goToResetPassword"
            >忘记密码？</el-link
          >
        </div>

        <div class="button-container">
          <el-button type="primary" @click="handleLogin">登录</el-button>
          <el-button type="warning" @click="reset">取消</el-button>
        </div>
      </el-form>
    </div>

    <!-- 底部版权信息 -->
    <div class="footer">
      <p class="slogan">中国专业科研服务引领</p>
      <p class="copyright">
        Copyright 软赢科技 All Rights Reserved 服务热线：188-888-8888
      </p>
      <p class="icp">
        <span>网安备 3301060201****号</span><br />
        <span>增值电信业务经营许可证：晋B2-202****7</span><br />
        <span>晋ICP备150***93号-1</span>
      </p>
    </div>
  </div>
</template>



<script>
import { login } from "@/api/syspt/syspt";

export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        uName: "",
        password: "",
      },
      loginRules: {
        uName: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      passwordVisible: false,
    };
  },
  methods: {
    reset() {
      this.loginForm = {
        uName: "",
        password: "",
      };
    },
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          // 调用登录接口
          login(this.loginForm)
            .then((response) => {
              if (response.code == 200) {
                // 登录成功，跳转到首页
                this.$router.push("/syshome");
              } else {
                // 登录失败，提示错误信息
                this.$message.error(response.message || "登录失败");
              }
            })
            .catch((error) => {
              // 处理网络错误
              this.$message.error("登录失败，请稍后重试");
            });
        } else {
          // 表单验证失败
          this.$message.error("请输入正确的用户名和密码");
        }
      });
    },
    goToHome() {
      this.$router.push("/syshome");
    },
    goToResetPassword() {
      this.$router.push("/sysresetpassword");
    },
  }
};



</script>
  
  <style scoped>
.login-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.header {
  height: 80px;
  padding-left: 12.5vw;
  display: flex;
  align-items: center;
  gap: 15px;
}

.back-icon {
  font-size: 24px;
  color: #409eff;
  cursor: pointer;
}

.back-icon:hover {
  color: #66b1ff; /* 悬停时稍微亮一点的蓝色 */
}

.logo-container {
  cursor: pointer;
}

.platform-title {
  font-size: 24px;
  font-weight: bold;
  color: #409eff;
}

.login-form {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
}

.el-form {
  width: 400px;
}

.login-title {
  text-align: center;
  margin-bottom: 30px;
  font-size: 28px;
  color: #333;
}

.password-input {
  position: relative;
}

.password-eye {
  cursor: pointer;
  font-size: 16px;
  color: #909399;
  margin-right: 10px;
  line-height: 40px;
}

.password-eye:hover {
  color: #409eff;
}

.forgot-password {
  text-align: right;
  margin: -10px 0 10px;
}

.button-container {
  display: flex;
  justify-content: center; /* 按钮居中对齐 */
  gap: 10px; /* 按钮之间的间距 */
}

.footer {
  height: 20vh;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #f5f5f5;
  padding: 20px 0;
}

.slogan {
  font-size: 16px;
  margin-bottom: 10px;
}

.copyright {
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
}

.icp {
  font-size: 12px;
  color: #999;
  line-height: 1.8;
}

/* 输入框样式优化 */
.el-input {
  margin-bottom: 0;
}

.el-input__inner {
  height: 45px;
}

.el-input__prefix {
  display: flex;
  align-items: center;
}
</style>